Omplus.base.define(Omplus.controllers.Controller, {
    omplusName:"jackpotsController"
});


/**
 * ******************************************************************
 * Player Search
 * *****************************************************************
 */

Omplus.base.define(Omplus.models.Model, {
    omplusName:"JackpotSearch",
    controller:"transactionsController",
    value:{
        "game_id":{
            omplusType:"Number"
        },
        delta:{
            omplusType:"Number",
            value:5
        },
        start:{
            omplusType:"Number",
            value:0
        }
    }
});

Omplus.models.JackpotSearchModelProto = Omplus.base.extend(Omplus.models.Object, {
    omplusType:"JackpotSearchModelProto",
    value:{
        "id_jackpots":{
            omplusType:"Number"
        },
        "game_id":{
            omplusType:"Number"
        },
        "value":{
            omplusType:"String"
        },
        "name":{
            omplusType:"String"
        },
        "banner_url":{
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"JackpotSearchResults",
    controller:"jackpotsController",
    value:{
        jackpots:{
            omplusType:"Array",
            omplusProto:"JackpotSearchModelProto"
        },
        total:{
            omplusType:"Number"
        }
    }
});

Omplus.models.JackpotProto = Omplus.base.extend(Omplus.models.Model, {
    omplusType:"JackpotProto",
    value:{
        "id_jackpots":{
            omplusType:"Number",
            nullable:true
        },
        "game_id":{
            omplusType:"Number",
            nullable:true
        },
        "value":{
            omplusType:"String",
            nullable:true
        },
        "name":{
            omplusType:"String"
        },
        "banner":{
            omplusType:"String",
            nullable:true
        },
        "url":{
            omplusType:"String",
            nullable:true
        },
        banner_url:{
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.models.SingleChooser, {
    omplusName:"jackpotChooser",
    controller:"jackpotsController",
    omplusProto:"JackpotProto"
});

Omplus.views.OpeningJackpotTabView = Omplus.base.extend(Omplus.views.OpeningTabView, {
    omplusType:"OpeningJackpotTabView",
    layout:{
        omplusType:"VerticalLayout",
        width:"300px"
    },
    controller:"jackpotsController",
    components:[
        {
            model:"jackpotChooser.current.id_jackpots",
            labelModel:"Assets.list.jackpots_id_label.localValue",
            inputType:"Label"
        },
        {
            model:"jackpotChooser.current.game_id",
            labelModel:"Assets.list.game_id_label.localValue",
            inputType:"Label"
        },
        {
            model:"jackpotChooser.current.value",
            labelModel:"Assets.list.value_label.localValue",
            inputType:"Label"
        },
        {
            model:"jackpotChooser.current.name",
            labelModel:"Assets.list.name_label.localValue",
            inputType:"Label"
        },
        {
            model:"jackpotChooser.current.banner_url",
            labelModel:"Assets.list.banner_label.localValue",
            inputType:"Image",
            height:"auto"
        }
    ]
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"orderingJackpotsModel",
    controller:"jackpotsController",
    value:{
        jackpots:{
            omplusType:"Array",
            omplusProto:"JackpotSearchModelProto"
        },
        order:{
            omplusType:"Array",
            omplusProto:"Number"
        }
    },
    actions:[
        {
            omplusType:"Get",
            omplusName:"getJackpotsForOrdering",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"orderingJackpotsModel",
            requestModel:"orderingJackpotsModel"
        },
        {
            omplusType:"Get",
            omplusName:"setJackpotsForOrdering",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"orderingJackpotsModel",
            requestModel:"orderingJackpotsModel"
        }
    ]
});

Omplus.base.define(Omplus.views.ManagementPanel, {
    omplusName:"jackpotsPanel",
    controller:"jackpotsController",
    renderTo:"managements",
    models:{
        chooser:"jackpotChooser",
        search:"JackpotSearch",
        searchResult:"JackpotSearchResults",
        searchResultList:"jackpots",
        forDisplay:"id_jackpots"
    },
    views:{
        chooser:{
            title:"Assets.list.jackpots_label.localValue",
            components:[
                {
                    omplusName:"jackpotTabs",
                    omplusType:"OpeningTabPanel",
                    omplusProto:"OpeningJackpotTabView",
                    controller:"jackpotsController",
                    model:"jackpotChooser",
                    showModel:"name"
                }
            ]
        },
        search:[
            {
                // Game Id
                model:"JackpotSearch.game_id",
                labelModel:"Assets.list.game_id_label.localValue"
            },
            {
                // Per page
                inputType:"Select",
                model:"PerPages",
                showModel:"number",
                current:"forTransactions",
                controller:"languageController",
                labelModel:"Assets.list.label_per_page.localValue",
                perPage:true
            },
            {
                // Search button
                inputType:"Button",
                controller:"languageController",
                model:"Assets.list.label_search_button.localValue",
                cssClasses:["search-button"],
                labelWidth:"0%",
                inputWidth:"100%",
                searchButton:true
            }
        ],
        searchResult:[
            {
                labelModel:"Assets.list.jackpots_id_label.localValue",
                width:"150px",
                omplusType:"Label",
                model:"id_jackpots"
            },
            {
                labelModel:"Assets.list.name_label.localValue",
                width:"250px",
                omplusType:"Label",
                model:"name"
            },

            {
                labelModel:"Assets.list.value_label.localValue",
                width:"80px",
                omplusType:"Label",
                model:"value"
            },
            {
                labelModel:"Assets.list.banner_label.localValue",
                width:"150px",
                omplusType:"Image",
                model:"banner_url"
            },
            {
                omplusType:"Button",
                model:"Assets.list.details_label.localValue",
                width:"250px",
                controller:"languageController",
                getDetails:true,
                errorable:false
            }
        ]
    },
    tableProto:{
        omplusType:"Panel",
        components:[
            {
                omplusName:"tableColumnNameLabels",
                omplusType:"Panel",
                components:[],
                cssClasses:[
                    "table-header"
                ]
            },
            {
                omplusType:"DinamicTable",
                orientation:"vertical",
                rowsPerPage:5,
                rowHeight:"auto",
                rowCellWidths:[]
            }
        ]
    },
    components:[
        {
            omplusType:"TabPanel",
            omplusName:"orderJackpotsPanel",
            layout:{
                omplusType:"HorizontalLayout"
            },
            controller:"languageController",
            model:"Assets.list.order_label.localValue",
            components:[
                {
                    omplusType:"Button",
                    omplusName:"getJackpotsForOrderingButton",
                    model:"Assets.list.label_search_button.localValue",
                    controller:"languageController",
                    click:function () {
                        Omplus.globals.getObject("orderingJackpotsModel").getAction("getJackpotsForOrdering").run();
                    }
                },
                {
                    omplusType:"Button",
                    omplusName:"saveJackpotsForOrderingButton",
                    model:"Assets.list.label_save_button.localValue",
                    controller:"languageController",
                    click:function () {
                        var array = Omplus.globals.getObject("SortableJackpots").toArray();
                        Omplus.globals.getObject("orderingJackpotsModel.order").setValue(array);
                        Omplus.globals.getObject("orderingJackpotsModel").getAction("setJackpotsForOrdering").run();
                    }
                },
                {
                    omplusType:"SortableList",
                    omplusName:"SortableJackpots",
                    renderTo:"orderJackpotsPanel",
                    model:"orderingJackpotsModel.jackpots",
                    controller:"jackpotsController",
                    forDisplay: "name",
                    forId:"id_jackpots"
                }
            ]
        }
    ]
});